﻿using Aker.DevTeam;
using DevExpress.XtraReports.UI;
using System;
using System.Data;
using System.Drawing;
using System.Drawing.Printing;

namespace Aker.Cikislar
{
    public partial class IrsaliyeReport : XtraReport
    {
        string detailTableName;

        private DataTable dtMaster;
        private DataTable dtDetail;
        private DataSet ds;

        public IrsaliyeReport(int CikisId)
        {
            InitializeComponent();

            ds = Data.DM.ExecuteDataSet("GetIrsaliye", CikisId);
            dtMaster = ds.Tables[0];
            dtDetail = ds.Tables[1];

            dtDetail.Columns.Add("#", typeof(int));
            for (int i = 0; i < dtDetail.Rows.Count; i++)
                dtDetail.Rows[i]["#"] = i + 1;


            detailTableName = dtDetail.TableName;
            DataRow dr = dtMaster.Rows[0];
            //string iNo = dr["IrsaliyeNo"].ToString();
            //lblSiraNo.Text = iNo.Split('-')[1];
            //lblSeri.Text = iNo.Split('-')[0];
            //lblSeri.Text = dr["Musteri"].ToStringNN(); 

            string adres1 = dr["MusteriAdresi"].ToString().Replace(" VD:", "<br><br> VD:");
            lblMusteriAdresi.Html = adres1;
            lblMusteriAdresi.Padding = new DevExpress.XtraPrinting.PaddingInfo(2, 0, 0, 0);
            lblMusteriAdresi.Font = lblTanzimTarihi.Font;

            string adres2 = dr["SevkAdresi"].ToString().Replace(" VD:", "<br><br> VD:");
            lblSevkAdresi.Html = adres2;
            lblSevkAdresi.Padding = new DevExpress.XtraPrinting.PaddingInfo(2, 0, 0, 0);
            lblSevkAdresi.Font = lblTanzimTarihi.Font;



            lblMusteri.Text = dr["Musteri"].ToString();
            lblSevkCari.Text = dr["SevkMusterisi"].ToString();
            lblTanzimTarihi.Text = ((DateTime)dr["TanzimTarihi"]).ToString("dd.MM.yyyy");
            lblSevkTarihi.Text = ((DateTime)dr["SevkTarihi"]).ToString("dd.MM.yyyy");

            if (lblMusteri.Text == lblSevkCari.Text)
                lblSevkCari.Text = "";

            if (lblMusteriAdresi.Text == lblSevkAdresi.Text)
                lblSevkAdresi.Text = lblSevkAdresi.Html = "";

            lblAciklama.Text = dr["Aciklama"].ToStringNN();


            PrintingSystem.PageSettings.Assign(new Margins(0, 0, 0, 0), new Margins(0, 0, 0, 0), PaperKind.A4, new Size(2800, 2100), false);
            PrintingSystem.ShowMarginsWarning = false;
        }




        private void Detail_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
        {
            this.DataSource = ds;
            this.DataMember = detailTableName;

            BindCell(dKartelaNo, "KartelaNo");
            BindCell(dPartiNo, "PartiNo");
            BindCell(dTopAdet, "TopAdet");
            BindCell(dMiktar, "Miktar");
            BindCell(dBirim, "Birim");
            BindCell(dMalinCinsi, "MalinCinsi");
            //BindCell(dBirimFiyati, "BirimFiyati");
            //BindCell(dTutari, "Tutari");
        }

        private void BindCell(XRTableCell cell, string columnName, string format = "")
        {
            if (format == "")
                cell.DataBindings.Add("Text", null, detailTableName + "." + columnName);
            else
                cell.DataBindings.Add("Text", null, detailTableName + "." + columnName, format);
        }

        private void OrderReport_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
        {
            //if (WithPictures)
            //    imgArticle.DataBindings.Add("Image", null, detailTableName + "." + "PhotoEmail");
            //else
            //{
            //    trDetail.Cells.Remove(detailPhoto);

            //    for (int i = 0; i < tblHeader.Rows[0].Cells.Count; i++)
            //    {
            //        tblDetail.Rows[0].Cells[i].WidthF = tblHeader.Rows[0].Cells[i].WidthF;
            //    }

            //    trDetail.HeightF = 10;
            //    Detail.HeightF = 10;
            //}
        }
    }
}